package cn.edu.ujn.park.service;

import cn.edu.ujn.park.dao.Book;
import cn.edu.ujn.park.dao.BookMapper;
import cn.edu.ujn.park.dao.User;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements IBookService{

    @Autowired
    private BookMapper bookMapper;
    @Override
    public Page<User> selectAll(Book book) {
        Page<User> page = new Page<>();
        List<User> list = bookMapper.selectAll(book);
        Integer count=bookMapper.selectCount(book);


        page.setPage(book.getStart());
        page.setRows(list);
        page.setSize(book.getRows());
        page.setTotal(count);

        return page;
    }

    @Override
    public void insert(Book book) {
        bookMapper.insert(book);
    }

    @Override
    public Book getBookById(Integer id) {
        return bookMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(Book book) {
        bookMapper.updateByPrimaryKeySelective(book);
    }

    @Override
    public void deleteByPrimaryKey(Integer id) {
        bookMapper.deleteByPrimaryKey(id);
    }
}
